//
//  SimpleViewController.swift
//  TestAPIManager
//
//  Created by yq on 2020/10/12.
//  Copyright © 2020 杨庆. All rights reserved.
//

import UIKit
import RxSwift
import RxCocoa

class SimpleViewController: UIViewController,UIImagePickerControllerDelegate {
    
    @IBOutlet weak var cameraOutlet: UIButton!   // 拍摄一张照片, 显示
    @IBOutlet weak var galleryOutlet: UIButton!  // 选择一张照片, 显示
    @IBOutlet weak var cropOutlet: UIButton!     // 选出照片编辑, 显示
    @IBOutlet weak var topImageViewOutlet: UIImageView! // 显示图片
    
    @IBOutlet weak var dismissButton: UIButton!
    
    let disposeBag = DisposeBag()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
             
        cameraOutlet.isEnabled = UIImagePickerController.isSourceTypeAvailable(.camera)

//        galleryOutlet.rx.tap
//            .flatMapLatest { [weak self] _ in
//                return UIImagePickerController.rx.createWithParent(self) { picker in
//                    picker.sourceType = .photoLibrary
//                    picker.allowsEditing = false
//                }
//                .flatMap {
//                    $0.rx.didFinishPickingMediaWithInfo
//                }
//                .take(1)
//            }
//            .map { info in
//                return info[.originalImage] as? UIImage
//            }
//            .bind(to: topImageViewOutlet.rx.image)
//            .disposed(by: disposeBag)

        
//        // 相册
//        galleryOutlet.rx.tap
//            .flatMapLatest { [weak self] _ in
//                return UIImagePickerController.rx.createWithParent(self) { picker in
//                    picker.sourceType = .photoLibrary
//                    picker.allowsEditing = false
//                }
//                .flatMap {
//                    $0.rx.didFinishPickingMediaWithInfo
//                }
//                .take(1)
//        }
//        .map { info in
//            return (info[.originalImage] as? UIImage)!
//        }
//        .bind(to: topImageViewOutlet.rx.image)
//        .disposed(by: disposeBag)
        
        // 退出
        dismissButton.rx.tap
            .subscribe(onNext:{[weak self] in
                self?.dismiss(animated: true , completion: nil)
            })
        .disposed(by: disposeBag)
    }
    
    
}


/**这里的相册拿不到图片信息*/
